﻿762.二进制表示中质数个计算置位
int number(int n) {
    int ret = 0;
    for (int i = 0; i < 32; i++)
    {
        if (((n >> i) & 1) == 1)
        {
            ret++;
        }
    }
    return ret;
}
int Prime(int n) {
    if (n < 2)
    {
        return 0;
    }
    for (int i = 2; i < n; i++)
    {
        if (n % i == 0)
        {
            return 0;
        }
    }
    return 1;
}
int countPrimeSetBits(int left, int right) {
    int ans = 0;
    for (int i = left; i <= right; i++)
    {
        int count = number(i);
        if (Prime(count) == 1)
        {
            ans++;
        }
    }
    return ans;
}

766.托普利茨矩阵
bool isToeplitzMatrix(int** matrix, int matrixSize, int* matrixColSize) {
    for (int i = 1; i < matrixSize; i++)
    {
        for (int j = 0; j < (*matrixColSize) - 1; j++)
        {
            if (matrix[i - 1][j] != matrix[i][j + 1])
            {
                return false;
            }
        }
    }
    return true;
}

796.旋转字符串
void swap(char* s, int l, int r) {
    while (l < r)
    {
        char temp = s[l];
        s[l] = s[r];
        s[r] = temp;
        l++;
        r--;
    }
}
bool rotateString(char* s, char* goal) {
    if (strlen(s) != strlen(goal))
    {
        return false;
    }

    for (int i = 0; i < strlen(s); i++)
    {
        char temp[101];
        strcpy(temp, s);
        swap(temp, 0, i);
        swap(temp, i + 1, strlen(temp) - 1);
        swap(temp, 0, strlen(temp) - 1);
        if (strcmp(temp, goal) == 0)
        {
            return true;
        }
    }
    return false;
}

